//
//  BaseTableViewController.swift
//  ydy_weibo
//
//  Created by 杨德勇 on 16/7/12.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VistorLoginViewDelegate {
    
    var userLogin = UserAccountViewModel().userLogin
    var vistorLoginView:VistorLoginView?
    
    //loadview 是苹果专门为手写代码准备的方法，等效于sb／xib
    //一旦实现这个方法，sb／xib会自动失效
    
    //loadview会自动检测view是否为空，如果nil就会再次调用loadview，如果一直nil就崩溃
    override func loadView() {
        userLogin ? super.loadView() : loadVistorView()
    }
    
    private func loadVistorView(){
        //view的大小会在 viewdidload中设置
        vistorLoginView = VistorLoginView()
        vistorLoginView?.vistorDelegate = self
        view = vistorLoginView
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: #selector(vistorWillLogin))
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(vistorWillRegister))
        //这里应该要设置navigation的颜色，但是为了后面也方便设置，直接把主题色改了，但是如果在这里写的话，要刷新视图才可以看见，所以要尽早设置，写在appdelegate里最好
        
    
    } 
    
    
    //MARK:-
    //MARK:代理方法
    func vistorWillLogin() {
        print("login")
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func vistorWillRegister() {
        print("register")
        
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}
